package com.huluobo.a2202mvvm_im_douyindemo.conversation;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2202mvvm_im_douyindemo.mvvmBase.BaseRepo;
import com.hyphenate.chat.EMConversation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by LC on 2024/4/26.
 */
public class ConversationRepo extends BaseRepo {
    public void loadConversations(MutableLiveData<List<EMConversation>> success, MutableLiveData<String> failed) {
        //获取所有会话列表,会话列表SDK提供的是一个map
        Map<String, EMConversation> allConversations = emClient.chatManager().getAllConversations();
        if (allConversations.size() == 0) {
            failed.postValue("获取会话列表失败");
            return;
        }
        //使用adapter展示数据需要的是一个List
        //newList的时候,可以直接把map中的值填给List,这样获得了一个保存map所有值的一个list
        List<EMConversation> conversationList = new ArrayList<>(allConversations.values());
        success.postValue(conversationList);
    }
}
